package com.cskaoyan.controller;

import com.cskaoyan.bean.ConfigMall;
import com.cskaoyan.bean.ExpressConfig;
import com.cskaoyan.bean.OrderConfig;
import com.cskaoyan.bean.WxConfig;
import com.cskaoyan.bean.basebean.BaseRespVo;

import com.cskaoyan.service.SystemConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


/**
 * @description: ${description}
 * @author: cuicui
 **/
@RestController
@RequestMapping("admin/config")
public class SystemConfigController {

    @Autowired
    SystemConfigService systemConfigService;

    @PostMapping("mall")
    @RequiresPermissions(value = "admin:config:mall:updateConfigs")
    public BaseRespVo mallConfig(@RequestBody ConfigMall configMall) throws IllegalAccessException {
        systemConfigService.configMall(configMall);
        return BaseRespVo.ok("成功");
    }

    @RequiresPermissions(value = "admin:config:mall:list")
    @GetMapping("mall")
    public BaseRespVo mallConfigView() throws IllegalAccessException {
        ConfigMall configMall = systemConfigService.showMallConfig();
        return BaseRespVo.ok(configMall,"成功");
    }

    @GetMapping("express")
    @RequiresPermissions(value = "admin:config:express:list")
    public BaseRespVo expressConfigView() throws IllegalAccessException {
        ExpressConfig expressConfig = systemConfigService.showExpressConfig();
        return BaseRespVo.ok(expressConfig,"成功");
    }

    @PostMapping("express")
    @RequiresPermissions(value = "admin:config:express:updateConfigs")
    public BaseRespVo expressConfig(@RequestBody ExpressConfig expressConfig) throws IllegalAccessException {
        systemConfigService.configExpress(expressConfig);
        return BaseRespVo.ok("成功");
    }

    @GetMapping("order")
    @RequiresPermissions(value = "admin:config:order:list")
    public BaseRespVo orderConfigView() throws IllegalAccessException {
        OrderConfig orderConfig = systemConfigService.showOrderConfig();
        return BaseRespVo.ok(orderConfig,"成功");
    }

    @PostMapping("order")
    @RequiresPermissions(value = "admin:config:order:updateConfigs")
    public BaseRespVo orderConfig(@RequestBody OrderConfig orderConfig) throws IllegalAccessException {
        systemConfigService.configOrder(orderConfig);
        return BaseRespVo.ok("成功");
    }

    @GetMapping("wx")
    @RequiresPermissions(value = "admin:config:wx:list")
    public BaseRespVo wxConfigView() throws IllegalAccessException {
        WxConfig wxConfig = systemConfigService.showWxConfig();
        return BaseRespVo.ok(wxConfig,"成功");
    }

    @PostMapping("wx")
    @RequiresPermissions(value = "admin:config:wx:updateConfigs")
    public BaseRespVo wxConfig(@RequestBody WxConfig wxConfig) throws IllegalAccessException {
        systemConfigService.configWx(wxConfig);
        return BaseRespVo.ok("成功");
    }
}
